home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Tools / MPW / gawk 2.11.1r3 / Sources / msg.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-05-26  |  3.3 KB  |  167 lines  |  [TEXT/MPS ]

  1. /*
  2.  * msg.c - routines for error messages
  3.  */
  4.  
  5. /* 
  6.  * Copyright (C) 1986, 1988, 1989 the Free Software Foundation, Inc.
  7.  * 
  8.  * This file is part of GAWK, the GNU implementation of the
  9.  * AWK Progamming Language.
  10.  * 
  11.  * GAWK is free software; you can redistribute it and/or modify
  12.  * it under the terms of the GNU General Public License as published by
  13.  * the Free Software Foundation; either version 1, or (at your option)
  14.  * any later version.
  15.  * 
  16.  * GAWK is distributed in the hope that it will be useful,
  17.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  19.  * GNU General Public License for more details.
  20.  * 
  21.  * You should have received a copy of the GNU General Public License
  22.  * along with GAWK; see the file COPYING.  If not, write to
  23.  * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  24.  */
  25.  
  26. /* 12May91    Matthias Neeracher    <neeri@iis.ethz.ch>    MPW port */
  27.  
  28. #include "awk.h"
  29.  
  30. int sourceline = 0;
  31. char *source = NULL;
  32.  
  33. /* VARARGS2 */
  34. static void
  35. err(s, msg, argp)
  36. char *s;
  37. char *msg;
  38. va_list *argp;
  39. {
  40.     int line;
  41.     char *file;
  42.  
  43. #ifndef macintosh
  44.     (void) fprintf(stderr, "%s: %s ", myname, s);
  45.     vfprintf(stderr, msg, *argp);
  46.     (void) fprintf(stderr, "\n");
  47.     line = (int) FNR_node->var_value->numbr;
  48.     if (line) {
  49.         (void) fprintf(stderr, " input line number %d", line);
  50.         file = FILENAME_node->var_value->stptr;
  51.         if (file && !STREQ(file, "-"))
  52.             (void) fprintf(stderr, ", file `%s'", file);
  53.         (void) fprintf(stderr, "\n");
  54.     }
  55.     if (sourceline) {
  56.         (void) fprintf(stderr, " source line number %d", sourceline);
  57.         if (source)
  58.             (void) fprintf(stderr, ", file `%s'", source);
  59.         (void) fprintf(stderr, "\n");
  60.     }
  61. #else
  62.     if (*s)
  63.         (void) fprintf(stderr, "%s ", s);
  64.     vfprintf(stderr, msg, *argp);
  65.     (void) fprintf(stderr, "\n");
  66.     line = (int) FNR_node->var_value->numbr;
  67.     if (line) {
  68.         file = FILENAME_node->var_value->stptr;
  69.         if (file && !STREQ(file, "-"))
  70.             (void) fprintf(stderr, "File '%s'; Line %d\n", file, line+1);
  71.         else
  72.             (void) fprintf(stderr, "# Input line %d\n", line+1);
  73.     }
  74.     if (sourceline) {
  75.         if (source)
  76.             (void) fprintf(stderr, "File '%s'; Line %d\n", source, sourceline);
  77.         else
  78.             (void) fprintf(stderr, "# Source line %d\n", sourceline+1);
  79.     }
  80. #endif
  81. }
  82.  
  83. /*VARARGS0*/
  84. #ifndef macintosh
  85. void
  86. msg(va_alist)
  87. va_dcl
  88. #else
  89. void
  90. msg(char * mesg)
  91. #endif
  92. {
  93.     va_list args;
  94. #ifndef macintosh
  95.     char *mesg;
  96. #endif
  97.  
  98. #ifndef macintosh
  99.     va_start(args);
  100.     mesg = va_arg(args, char *);
  101.     err("", mesg, &args);
  102.     va_end(args);
  103. #else
  104.     va_start(args, mesg);
  105.     err("", mesg, &args);
  106.     va_end(args);
  107. #endif
  108. }
  109.  
  110. /*VARARGS0*/
  111. #ifndef macintosh
  112. void
  113. warning(va_alist)
  114. va_dcl
  115. #else
  116. void
  117. warning(char * mesg)
  118. #endif
  119. {
  120.     va_list args;
  121. #ifndef macintosh
  122.     char *mesg;
  123. #endif
  124.  
  125. #ifndef macintosh
  126.     va_start(args);
  127.     mesg = va_arg(args, char *);
  128.     err("warning:", mesg, &args);
  129.     va_end(args);
  130. #else
  131.     va_start(args, mesg);
  132.     err("# Warning:", mesg, &args);
  133.     va_end(args);
  134. #endif
  135. }
  136.  
  137. /*VARARGS0*/
  138. #ifndef macintosh
  139. void
  140. fatal(va_alist)
  141. va_dcl
  142. #else
  143. void
  144. fatal(char * mesg)
  145. #endif
  146. {
  147.     va_list args;
  148. #ifndef macintosh
  149.     char *mesg;
  150. #endif
  151.  
  152. #ifndef macintosh
  153.     va_start(args);
  154.     mesg = va_arg(args, char *);
  155.     err("fatal error:", mesg, &args);
  156.     va_end(args);
  157. #else
  158.     va_start(args, mesg);
  159.     err("# Fatal error:", mesg, &args);
  160.     va_end(args);
  161. #endif
  162. #ifdef DEBUG
  163.     abort();
  164. #endif
  165.     exit(1);
  166. }
  167.